export default {
	data() {
		return {
			currentPage: 1, //加载下一页默认请求从第二页开始
			totalCount: null, //总数据条数
			totalPage: null, //总页数
			listContainer: 0, //列表容器距离顶部的初始距离
		}
	},
	onLoad() {},
	onReachBottom() {
		if (this.currentPage == this.totalPage) {
			this.$refs.pageHelperRef.loadingText = '—— 最后一页 ——'
			this.$refs.pageHelperRef.loadingIcon = false; //隐藏加载数据时的加载态
		}
		this.currentPage += 1; //请求页码递增
		this.init(this.currentPage);
	},
	methods: {
		//刷新操作时初始化部分数据
		refresh() {
			let that = this;
			this.currentPage = 1; //恢复请求页码为第一页；
			this.$refs.pageHelperRef.loadingText = '加载中';
			this.$refs.pageHelperRef.loadingIcon = true; //隐藏加载数据时的加载态
			//当请求无响应或404等隐藏刷新动画
			setTimeout(function() {
				that.$refs.pageHelperRef.refreshIconTop = -40;
			}, 400)
		},
		//请求成功隐藏下拉刷新加载动画
		hideRefreshIcon(res) {
			let that = this;
			if (res) {
				setTimeout(function() {
					that.$refs.pageHelperRef.refreshIconTop = -40
				}, 400)
			}
		},
		//请求异常时隐藏加载动画并提示
		handlerException(err) {
			this.$refs.pageHelperRef.loadingIcon = false;
			this.$refs.pageHelperRef.loadingText = '请求异常';
		},
		//如顶部有搜索框或导航条等，需调用此方法传入最外层选择器的名称
		calcTopDistance(selectors) {
			let that = this;
			let topDistance = null;
			const query = uni.createSelectorQuery().in(that);
			query
				.select(selectors)
				.boundingClientRect(data => {
					// console.log('得到布局位置信息' + JSON.stringify(data));
				})
				.exec(res => {
					that.listContainer = res[0].height
				});
			return that.listContainer
		}
	}
}
